<?php
namespace Mobile\Controller;

use Common\Controller\UserBaseController;

/**
 * 首页控制器
 */
class DayresultController extends UserBaseController
{

    /**
     *  获取当天所有期数开奖结果
     */
    public function index()
    {
        $c_type = $_GET['lottery'];
        $g_time = $_GET['_'];
        $data   = array();
        $day    = date();
        header('Content-type:text/json');
        switch ($c_type) {
            //幸运飞艇
            case 'XYFT': //幸运飞艇 彩种id 5
                $open_time = S('op_time_5');

                if (empty($open_time)) {
                    $condition1['c_id'] = 5;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_5', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[180]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 5;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //北京PK10
            case 'BJPK10': //北京PK10 彩种id 4
                $open_time = S('op_time_4');

                if (empty($open_time)) {
                    $condition1['c_id'] = 4;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_4', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[180]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 4;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();

                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //重庆时时彩
            case 'CQSSC': //重庆时时彩 彩种id 1
                $open_time = S('op_time_1');

                if (empty($open_time)) {
                    $condition1['c_id'] = 1;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_1', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[120]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 1;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;

            //新疆时时彩
            case 'XJSSC': //新疆时时彩 彩种id 2
                $open_time = S('op_time_2');

                if (empty($open_time)) {
                    $condition1['c_id'] = 2;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_2', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[120]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 2;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //天津时时彩
            case 'TJSSC': //天津时时彩 彩种id 3
                $open_time = S('op_time_3');

                if (empty($open_time)) {
                    $condition1['c_id'] = 3;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_3', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[84]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 3;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //重庆幸运农场
            case 'XYNC': //重庆幸运农场 彩种id 8
                $open_time = S('op_time_8');

                if (empty($open_time)) {
                    $condition1['c_id'] = 8;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_8', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[97]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 8;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //广东快乐十分
            case 'GDKLSF': //广东快乐十分 彩种id 6
                $open_time = S('op_time_6');

                if (empty($open_time)) {
                    $condition1['c_id'] = 6;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_6', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[84]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 6;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //广西快三
            case 'GXK3': //广西快三 彩种id 7
                $open_time = S('op_time_7');

                if (empty($open_time)) {
                    $condition1['c_id'] = 7;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_7', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[78]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 7;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //PC蛋蛋
            case 'PCEGG': //PC蛋蛋 彩种id 11
                $open_time = S('op_time_11');

                if (empty($open_time)) {
                    $condition1['c_id'] = 11;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_11', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[179]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 11;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //北京快8
            case 'BJKL8': //北京快8 彩种id 9
                $open_time = S('op_time_9');

                if (empty($open_time)) {
                    $condition1['c_id'] = 9;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_9', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[179]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 9;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            //广西快乐十分
            case 'GXKLSF': //广西快乐十分 彩种id 10
                $open_time = S('op_time_10');

                if (empty($open_time)) {
                    $condition1['c_id'] = 10;
                    $op_time            = M('open_time')->where($condition1)->getField('data');
                    $open_time          = unserialize($op_time);

                    S('op_time_10', $open_time);
                }
                $start_time = strtotime($day . ' ' . $open_time[1]['kp_time']);
                $end_time   = strtotime($day . ' ' . $open_time[50]['kj_time']) + 3 * 60;
                //print_r($open_time);exit;
                $condition['c_id']     = 10;
                $condition['add_time'] = array(array('gt', $start_time), array('lt', $end_time));
                $result                = M('lottery_results')->where($condition)->select();
                foreach ($result as $k => $v) {
                    $data[$k]['drawNumber'] = $v['c_no'];
                    $data[$k]['drawTime']   = $v['add_time'] . '000';
                    $data[$k]['result']     = $v['lottery_result'];
                    $data[$k]['detail']     = $v['detail'];
                }
                echo json_encode($data);exit(0);
                break;
            default:echo json_encode($data);exit(0);
                break;

        }

    }

}
